testList1() {
  List<String> list = ['a', 'b', 'c'];
  for (int i = 0; i < list.length; i++) {
    print(list[i]);
  }
  for (String s in list) {
    print(s);
  }
  list.forEach((element) {
    print(element);
  });
  list.map((e) => e).toList();

  for (var entry in list.asMap().entries) {
    print('index: ${entry.key}, value: ${entry.value}');
  }
  list.asMap().forEach((index, value) {
    print('$index => $value');
  });
}

testMap() {
  Map<String, int> map = {'a': 1, 'b': 2};
  map.forEach((key, value) {
    print('key: $key, value: $value');
  });
  for (var entry in map.entries) {
    print('${entry.key} => ${entry.value}');
  }
  for (var key in map.keys) {
    print('key: $key');
  }

  for (var value in map.values) {
    print('value: $value');
  }
}

testList2() async {
  List<int> list = [1, 2, 3];

  list.where((_) {
    return false;
  });
  list.map((_) {
    return 1;
  });
  var result = list.fold(10, (previousValue, element) {
    return previousValue + element;
  });
  print('JtTag:result:$result');
  final result1 = await Stream.fromIterable(['Year', 2021, 12, 24, 'Dart'])
      .contains('Dart');

  final result2 = await Stream.fromIterable([1, 2, 3]).drain(100);
  print(result2);
}
testSet(){
  Set<String> fruits = {'apple', 'banana', 'orange'};
  // 1. for-in 遍历（最常用)
  for (var fruit in fruits) {
    print(fruit);
  }
  Set<int> numbers = {1, 2, 3};
  // 2. forEach 遍历
  numbers.forEach((num) {
    print(num);
  });
  // 3. 传统 for 循环（结合 toList）
  Set<String> names = {'Tom', 'Jerry', 'Spike'};
  List<String> nameList = names.toList();

  for (int i = 0; i < nameList.length; i++) {
    print('$i: ${nameList[i]}');
  }
//   4. 使用 Iterator（迭代器）
  Set<int> nums = {10, 20, 30};
  Iterator<int> iterator = nums.iterator;

  while (iterator.moveNext()) {
    print(iterator.current);
  }
//   5. 使用 map 转换 + 遍历
  Set<int> numsa = {1, 2, 3};

  numsa.map((e) => e * e).forEach((square) {
    print(square);
  });
}

void main() {
// test1();
  testSet();
}
